package simulator;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
 * Simulates the behavior of an electronic compass placed on the 
 * Robot at its center--points to "magnetic north"
 * @author anand
 *
 */
public class Compass extends Sensor{

	public Compass(Environment e) {
		super(e);
	}
	
	//@Override
	public String getName() {
		return "Compass";
	}

	public int getID(){
		return 4;
	}

	public void paint(Graphics g){
		g.setColor(Color.RED);
		Graphics2D g2d = (Graphics2D) g;
		g2d.setStroke(new BasicStroke(3));
		g.drawLine((int)env.robotX, (int)env.robotY,
				(int)(env.robotX), 
				(int)(env.robotY - 5));
		g2d.setStroke(new BasicStroke(1));
	}

	//@Override
	public double[] read(int magicnum) {
		double[] d = new double[2];
		d[0] = (Math.toDegrees(this.env.robotAngle)%360 > 0? 
				Math.toDegrees(this.env.robotAngle)%360 : 
					360+Math.toDegrees(this.env.robotAngle)%360);
		d[1] = Simulator.time;
		setState(d);
		return d;
	}

}
